package org.example;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RequestController {

    @RequestMapping("/request")
    public String request(HttpServletRequest request){

        //1.获取请求方式
        String method = request.getMethod();//GET
        System.out.println("method:"+method);

        //2.获取请求url地址
        String url = request.getRequestURL().toString();//http://localhost:8080/request
        System.out.println("url:"+url);
        //uri拿到的是资源的访问路径
        String uri = request.getRequestURI();
        System.out.println("uri:"+uri);//"/request"

        //3.获取请求协议
        String protocol = request.getProtocol();
        System.out.println("protocol:"+protocol);//"HTTP/1.1"

        //4.获取请求参数 - name,age
        String name = request.getParameter("name");
        System.out.println("name:"+name);
        String age = request.getParameter("age");
        System.out.println("age:"+age);

        //5.获取请求头 - Accept
        String accept = request.getHeader("Accept");
        System.out.println("accept:"+accept);

        return "OK";
    }


}
